import { createBrowserRouter } from "react-router-dom";

// 导入路由组件
import Reg, { action as regAction } from "@/views/auth/reg.tsx";
import Login, { action as loginAction } from "@/views/auth/login.tsx";
import Root, { loader as rootLoader } from "@/views/root/root.tsx";
import AuthLayout from "@/views/auth/auth-layout";
import AuthRoot from "@/components/root/auth-root";
import Home from "@/views/home/home.tsx";
import UserInfo, { action as userInfoAction } from "@/views/user/user-info";
import UserPassword, { action as userPwdAction } from "@/views/user/user-password";
import UserAvatar, { action as userAvatarAction } from "@/views/user/user-avatar";
import ArticleCate, { loader as artCateLoader, action as artCateAction } from "@/views/article/article-cate";
import ArticleList, { loader as artListLoader, action as artListAction } from "@/views/article/article-list";
import ArticleAdd, { loader as artAddLoader, action as artAddAction } from "@/views/article/article-add";
import ArticleEdit, { loader as artEditLoader, action as artEditAction } from "@/views/article/article-edit";

const router = createBrowserRouter([
  {
    path: "/reg",
    action: regAction,
    element: (
      <AuthLayout>
        <Reg />
      </AuthLayout>
    ),
  },
  {
    path: "/login",
    action: loginAction,
    element: (
      <AuthLayout>
        <Login />
      </AuthLayout>
    ),
  },
  {
    path: "/",
    element: (
      <AuthRoot>
        <Root />
      </AuthRoot>
    ),
    loader: rootLoader,
    children: [
      // 索引路由
      { index: true, element: <Home /> },
      { path: "home", element: <Home /> },
      { path: "user-info", element: <UserInfo />, action: userInfoAction },
      { path: "user-pwd", element: <UserPassword />, action: userPwdAction },
      { path: "user-avatar", element: <UserAvatar />, action: userAvatarAction },
      { path: "art-cate", element: <ArticleCate />, loader: artCateLoader, action: artCateAction },
      { path: "art-list", element: <ArticleList />, loader: artListLoader, action: artListAction },
      { path: "art-add", element: <ArticleAdd />, loader: artAddLoader, action: artAddAction, shouldRevalidate: () => false },
      { path: "art-edit/:id", element: <ArticleEdit />, loader: artEditLoader, action: artEditAction, shouldRevalidate: () => false },
    ],
  },
]);

export default router;
